package com.jt.provider.controller;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;//基于日志门面模式的一组api
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
//添加注解@Slf4j会自动构建日志对象
@Slf4j    //lombok中的这个注解用于告诉lombok
@RefreshScope //此注解描述类时，用于告诉系统底层，当配置中心内容发生变化，此对象要重新构建
@RestController
public class ProviderLogController {

    @Value("${logging.level.com.jt:debug}")
    private String logLevel;

    @GetMapping("/provider/log/doGetLogLevel")
    public String getLogLevel(){
        return "log level is "+logLevel;
    }

    @GetMapping("/provider/log/doLog02")
    public String doLog02(){
        log.info("log level is {}",logLevel);//内部感知
        return "log level is "+logLevel;//外部感知
    }


    //构建日志对象
    //private static final Logger log=
            //LoggerFactory.getLogger(ProviderLogController.class);
                    //getLogger("com.jt.provider.controller.ProviderLogController");
    //http://localhost:8081/provider/log/doLog01
    @GetMapping("/provider/log/doLog01")
    public String doLog01(){
        System.out.println("==doLog01==");
        log.trace("==trace==");
        log.debug("==debug==");
        //默认显示级别
        //info>warn>error
        log.info("==info==");
        log.warn("==warn==");
        log.error("==error==");
        return "log config text --01";
    }
}
